package com.yspa.yspa.dao.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.hsnn.medstgmini.dao.HibernateSqlUtil;
import com.hsnn.medstgmini.dao.HibernateSqlUtil2;
import com.hsnn.medstgmini.util.Pagination;
import com.hsnn.medstgmini.util.ParseDate;
import com.yspa.yspa.dao.YspaInterfaceDao;
@Repository
public class YspaInterfaceDaoImpl implements YspaInterfaceDao {

	@Autowired
	private HibernateSqlUtil2 dao;
	@Autowired
	private HibernateSqlUtil mydao;
	
	@Override
	public Map<String, Object> getUserInfo(Map<String, String> map) {
		StringBuffer sql = new StringBuffer();
		sql.append("select * from employees where 1=1");
		Map<String, Object> params = new HashMap<String, Object>();
		if (StringUtils.isNotBlank(map.get("userno"))){
			sql.append(" and userno = :userno");
			params.put("userno", map.get("userno"));
		}
		if (StringUtils.isNotBlank(map.get("userid"))){
			sql.append(" and userid = :userid");
			params.put("userid", map.get("userid"));
		}
		if (StringUtils.isNotBlank(map.get("passwd"))){
			sql.append(" and passwd = :passwd");
			params.put("passwd", map.get("passwd"));
		}
		if (StringUtils.isNotBlank(map.get("name"))){
			sql.append(" and name like :name");
			params.put("name", "%" + map.get("name") + "%");
		}
		List<Map<String,Object>> userList = (List<Map<String, Object>>) dao.getSqlList(sql.toString(), params);
		if(userList != null && userList.size() > 0){
			return userList.get(0);
		}
		return null;
	}
	
	@Override
	public Pagination getUserInfoList(Pagination page) {
		StringBuffer sql = new StringBuffer();
		sql.append("select * from employees where 1=1");
		Map<String, Object> params = new HashMap<String, Object>();
		Map<String, String> map = page.getConditions();
		if (StringUtils.isNotBlank(map.get("userno"))){
			sql.append(" and userno = :userno");
			params.put("userno", map.get("userno"));
		}
		if (StringUtils.isNotBlank(map.get("userid"))){
			sql.append(" and userid = :userid");
			params.put("userid", map.get("userid"));
		}
		if (StringUtils.isNotBlank(map.get("passwd"))){
			sql.append(" and passwd = :passwd");
			params.put("passwd", map.get("passwd"));
		}
		if (StringUtils.isNotBlank(map.get("name"))){
			sql.append(" and name like :name");
			params.put("name", "%" + map.get("name") + "%");
		}
		if (StringUtils.isNotBlank(map.get("passwd"))){
			sql.append(" and passwd = :passwd");
			params.put("passwd",  map.get("passwd"));
		}
		return dao.getSqlPageMapList(sql.toString(), params, page);
	}
	public Pagination getHactivityList(Pagination page) {
		StringBuffer sql = new StringBuffer();
		sql.append("select * from Hactivity where 1=1");
		Map<String, Object> params = new HashMap<String, Object>();
		Map<String, String> map = page.getConditions();
		if (StringUtils.isNotBlank(map.get("acttitle"))){
			sql.append(" and acttitle like :acttitle");
			params.put("acttitle", "%" + map.get("acttitle") + "%");
		}
		if (StringUtils.isNotBlank(map.get("name"))){
			sql.append(" and name like :name");
			params.put("name", "%" + map.get("name") + "%");
		}
		sql.append(" order by actbdate desc");
		return dao.getSqlPageMapList(sql.toString(), params, page);
	}
	public Pagination getHPProEventList(Pagination page) {
		StringBuffer sql = new StringBuffer();
		sql.append("select * from HP_pro_event where 1=1");
		Map<String, Object> params = new HashMap<String, Object>();
		Map<String, String> map = page.getConditions();
		if (StringUtils.isNotBlank(map.get("event_subject"))){
			sql.append(" and event_subject like :event_subject");
			params.put("event_subject", "%" + map.get("event_subject") + "%");
		}
		if (StringUtils.isNotBlank(map.get("event_place"))){
			sql.append(" and event_place like :event_place");
			params.put("event_place", "%" + map.get("event_place") + "%");
		}
		if (StringUtils.isNotBlank(map.get("userno"))){
			sql.append(" and userno = :userno");
			params.put("userno", map.get("userno"));
		}
		if (StringUtils.isNotBlank(map.get("strTime"))){
			sql.append(" and event_date >= :strTime");
			params.put("strTime", map.get("strTime"));
		}
		if (StringUtils.isNotBlank(map.get("endTime"))){
			sql.append(" and event_date <= :endTime");
			params.put("endTime", map.get("endTime"));
		}
		return dao.getSqlPageMapList(sql.toString(), params, page);
	}
	public Pagination getHPMedicineSugList(Pagination page) {
		StringBuffer sql = new StringBuffer();
		sql.append("select * from HP_medicine_sug where 1=1");
		Map<String, Object> params = new HashMap<String, Object>();
		Map<String, String> map = page.getConditions();
		if (StringUtils.isNotBlank(map.get("medicine_name"))){
			sql.append(" and medicine_name like :medicine_name");
			params.put("medicine_name", "%" + map.get("medicine_name") + "%");
		}
		if (StringUtils.isNotBlank(map.get("medicine_item"))){
			sql.append(" and medicine_item like :medicine_item");
			params.put("medicine_item", "%" + map.get("medicine_item") + "%");
		}
		if (StringUtils.isNotBlank(map.get("medicine_mode"))){
			sql.append(" and medicine_mode like :medicine_mode");
			params.put("medicine_mode", "%" + map.get("medicine_mode") + "%");
		}
		if (StringUtils.isNotBlank(map.get("userno"))){
			sql.append(" and userno = :userno");
			params.put("userno", map.get("userno"));
		}
		if (StringUtils.isNotBlank(map.get("strTime"))){
			sql.append(" and start_date >= :strTime");
			params.put("strTime", map.get("strTime"));
		}
		if (StringUtils.isNotBlank(map.get("endTime"))){
			sql.append(" and start_date <= :endTime");
			params.put("endTime", map.get("endTime"));
		}
		sql.append(" order by rowid desc");
		return dao.getSqlPageMapList(sql.toString(), params, page);
	}
	public Pagination getCalendarlogList(Pagination page) {
		StringBuffer sql = new StringBuffer();
		sql.append("select * from hp_reminder where 1=1");
		Map<String, Object> params = new HashMap<String, Object>();
		Map<String, String> map = page.getConditions();
		if (StringUtils.isNotBlank(map.get("descr"))){
			sql.append(" and descr like :descr");
			params.put("descr", "%" + map.get("descr") + "%");
		}
		if (StringUtils.isNotBlank(map.get("userno"))){
			sql.append(" and pro_userno = :userno");
			params.put("userno", map.get("userno"));
		}
		if (StringUtils.isNotBlank(map.get("strTime"))){
			sql.append(" and CreateDate >= :strTime");
			params.put("strTime", map.get("strTime"));
		}
		if (StringUtils.isNotBlank(map.get("endTime"))){
			sql.append(" and CreateDate <= :endTime");
			params.put("endTime", map.get("endTime"));
		}
		sql.append(" order by rowid desc");
		return dao.getSqlPageMapList(sql.toString(), params, page);
	}
	public Pagination getMeasempList(Pagination page) {
		StringBuffer sql = new StringBuffer();
		sql.append("select * from measemp where 1=1");
		Map<String, Object> params = new HashMap<String, Object>();
		Map<String, String> map = page.getConditions();
		if (StringUtils.isNotBlank(map.get("measure_id"))){
			sql.append(" and measure_id = :measure_id");
			params.put("measure_id", map.get("measure_id"));
		}
		if (StringUtils.isNotBlank(map.get("userno"))){
			sql.append(" and userno = :userno");
			params.put("userno", map.get("userno"));
		}
		if (StringUtils.isNotBlank(map.get("strTime"))){
			sql.append(" and datadate >= :strTime");
			params.put("strTime", map.get("strTime"));
		}
		if (StringUtils.isNotBlank(map.get("endTime"))){
			sql.append(" and datadate <= :endTime");
			params.put("endTime", map.get("endTime"));
		}
		return dao.getSqlPageMapList(sql.toString(), params, page);
	}
	public Pagination getHPKnowledgeList(Pagination page) {
		StringBuffer sql = new StringBuffer();
		sql.append("select * from HP_Knowledge where 1=1");
		Map<String, Object> params = new HashMap<String, Object>();
		Map<String, String> map = page.getConditions();
		if (StringUtils.isNotBlank(map.get("title"))){
			sql.append(" and title like :title");
			params.put("title", "%" + map.get("title") + "%");
		}
		if (StringUtils.isNotBlank(map.get("type"))){
			sql.append(" and type = :type");
			params.put("type", map.get("type"));
		}
		sql.append(" order by create_date desc ");
		return dao.getSqlPageMapList(sql.toString(), params, page);
	}
	public Pagination getFoodcalorList(Pagination page) {
		StringBuffer sql = new StringBuffer();
		sql.append("select * from Foodcalor where 1=1");
		Map<String, Object> params = new HashMap<String, Object>();
		Map<String, String> map = page.getConditions();
		if (StringUtils.isNotBlank(map.get("descr"))){
			sql.append(" and descr like :descr");
			params.put("descr", "%" + map.get("descr") + "%");
		}
		if (StringUtils.isNotBlank(map.get("classcd"))){
			sql.append(" and classcd = :classcd");
			params.put("classcd", map.get("classcd"));
		}
		return dao.getSqlPageMapList(sql.toString(), params, page);
	}
	public Pagination getFoodclassList(Pagination page) {
		StringBuffer sql = new StringBuffer();
		sql.append("select * from Foodclass where 1=1");
		Map<String, Object> params = new HashMap<String, Object>();
		Map<String, String> map = page.getConditions();
		if (StringUtils.isNotBlank(map.get("descr"))){
			sql.append(" and descr like :descr");
			params.put("descr", "%" + map.get("descr") + "%");
		}
		return dao.getSqlPageMapList(sql.toString(), params, page);
	}
	public Pagination getFoodempList(Pagination page) {
		StringBuffer sql = new StringBuffer();
		sql.append("select * from foodemp where userno=:userno");
		Map<String, Object> params = new HashMap<String, Object>();
		Map<String, String> map = page.getConditions();
		params.put("userno", map.get("userno"));
		if (StringUtils.isNotBlank(map.get("descr"))){
			sql.append(" and descr like :descr");
			params.put("descr", "%" + map.get("descr") + "%");
		}
		if (StringUtils.isNotBlank(map.get("datadate"))){
			sql.append(" and datadate = :datadate");
			params.put("datadate",  map.get("datadate") );
		}
		return dao.getSqlPageMapList(sql.toString(), params, page);
	}
	
	public Pagination getExerempList(Pagination page) {
		StringBuffer sql = new StringBuffer();
		sql.append("select * from exeremp where userno=:userno");
		Map<String, Object> params = new HashMap<String, Object>();
		Map<String, String> map = page.getConditions();
		params.put("userno", map.get("userno"));
		if (StringUtils.isNotBlank(map.get("descr"))){
			sql.append(" and descr like :descr");
			params.put("descr", "%" + map.get("descr") + "%");
		}
		if (StringUtils.isNotBlank(map.get("datadate"))){
			sql.append(" and datadate = :datadate");
			params.put("datadate",  map.get("datadate") );
		}
		return dao.getSqlPageMapList(sql.toString(), params, page);
	}
	public Pagination getEmpimeiList(Pagination page) {
		StringBuffer sql = new StringBuffer();
		sql.append("select * from exeremp where 1=1");
		Map<String, Object> params = new HashMap<String, Object>();
		Map<String, String> map = page.getConditions();
		if (StringUtils.isNotBlank(map.get("items"))){
			sql.append(" and items = :items");
			params.put("items",  map.get("descr") );
		}
		if (StringUtils.isNotBlank(map.get("name"))){
			sql.append(" and name like :name");
			params.put("name", "%" + map.get("name") + "%" );
		}
		return dao.getSqlPageMapList(sql.toString(), params, page);
	}
	
	public Map<String, Object> getUserInfo(Long userno){
		String sql = "SELECT * FROM employees WHERE userno= :userno";
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("userno", userno);
		List<Map<String, Object>> list = (List<Map<String, Object>>) dao.getSqlMapList(sql, params);
		if (null != list && list.size() > 0){
			return list.get(0);
		}
		return null;
	}
	public void regditUserInfo(Pagination page){
		StringBuffer sql = new StringBuffer();
		sql.append("INSERT INTO employees(userid,name,nickname,birthdate,telephone,cellphone,email,sex,bucd,deptname,updid,upddate,user_guid,trial,passwd)")
		.append(" VALUES (:userid,:name,:nickname,:birthdate,:telephone,:cellphone,:email,:sex,:bucd,:deptname,:updid,getdate(),:user_guid,0,:passwd)");
		Map<String, Object> params = new HashMap<String, Object>();
		String userguid = UUID.randomUUID().toString();
		params.put("userid", page.getConditions().get("userid"));
		params.put("name", page.getConditions().get("name"));
		params.put("nickname", page.getConditions().get("nickname"));
		params.put("birthdate", ParseDate.fromShortFormat(page.getConditions().get("birthdate")));
		params.put("telephone", page.getConditions().get("cellphone"));
		params.put("cellphone", page.getConditions().get("cellphone"));
		params.put("email", page.getConditions().get("email"));
		params.put("sex", page.getConditions().get("sex"));
		params.put("bucd", "wkhm");
		params.put("deptname", "试用会员");
		params.put("updid", userguid);
		params.put("user_guid", userguid);
		params.put("passwd", page.getConditions().get("password"));
		dao.executeSql(sql.toString(), params);
	}
	public void updateUserInfo(Pagination page){
		StringBuffer sql = new StringBuffer();
		Map<String, Object> params = new HashMap<String, Object>();
		sql.append("UPDATE employees SET ");
		if (StringUtils.isNotBlank(page.getConditions().get("duedate"))){
			sql.append(" duedate = :duedate,");
			params.put("duedate", ParseDate.fromShortFormat(page.getConditions().get("duedate")));
		}
		if (StringUtils.isNotBlank(page.getConditions().get("height"))){
			sql.append(" height = :height,");
			params.put("height", page.getConditions().get("height"));
		}
		if (StringUtils.isNotBlank(page.getConditions().get("weight"))){
			sql.append(" weight = :weight,");
			params.put("weight", page.getConditions().get("weight"));
		}
		if (StringUtils.isNotBlank(page.getConditions().get("ContactName"))){
			sql.append(" ContactName = :ContactName,");
			params.put("ContactName", page.getConditions().get("ContactName"));
		}
		if (StringUtils.isNotBlank(page.getConditions().get("ContactRelationship"))){
			sql.append(" ContactRelationship = :ContactRelationship,");
			params.put("ContactRelationship", page.getConditions().get("ContactRelationship"));
		}
		if (StringUtils.isNotBlank(page.getConditions().get("ContactRelationship"))){
			sql.append(" ContactMobile = :ContactMobile,");
			params.put("ContactMobile", page.getConditions().get("ContactMobile"));
		}
		if (StringUtils.isNotBlank(page.getConditions().get("imei"))){
			sql.append(" imei = :imei,");
			params.put("imei", page.getConditions().get("imei"));
		}
		if (StringUtils.isNotBlank(page.getConditions().get("imei2"))){
			sql.append(" imei2 = :imei2,");
			params.put("imei2", page.getConditions().get("imei2"));
		}
		if (StringUtils.isNotBlank(page.getConditions().get("imei3"))){
			sql.append(" imei3 = :imei3,");
			params.put("imei3", page.getConditions().get("imei3"));
		}
		if(sql.substring(sql.length() - 1, sql.length()).equals(",")){
			sql = new StringBuffer(sql.substring(0, sql.length() - 1));
		}
		sql.append(" WHERE userno = :userno");
		params.put("userno", page.getConditions().get("userno"));
		dao.executeSql(sql.toString(), params);
	}
	@Override
	public void updateUserIMEI(Pagination page) {
		StringBuffer sql = new StringBuffer();
		Map<String, Object> params = new HashMap<String, Object>();
		sql.append("UPDATE employees SET ");
		sql.append(" imei = :imei,");
		params.put("imei", page.getConditions().get("imei"));
		sql.append(" imei2 = :imei2,");
		params.put("imei2", page.getConditions().get("imei2"));
		sql.append(" imei3 = :imei3");
		params.put("imei3", page.getConditions().get("imei3"));
		sql.append(" WHERE userno = :userno");
		params.put("userno", page.getConditions().get("userno"));
		dao.executeSql(sql.toString(), params);
	}
	public Map<String, Object> getEmpimeiInfo(Long rowid){
		String sql = "SELECT * FROM empimei WHERE rowid = :rowid";
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("rowid", rowid);
		List<Map<String, Object>> list = (List<Map<String, Object>>) dao.getSqlMapList(sql, params);
		if (null != list && list.size() > 0){
			return list.get(0);
		}
		return null;
	}
	public void updateEmpimeiInfo(Pagination page){
		String sql = "UPDATE empimei SET name=:name,imei=:imei WHERE rowid=:rowid";
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("name", page.getConditions().get("name"));
		params.put("imei", page.getConditions().get("imei"));
		params.put("rowid", page.getConditions().get("rowid"));
		dao.executeSql(sql, params);
	}
	public void updatePasswd(String userno, String passwd){
		String sql = "UPDATE employees SET passwd=:passwd WHERE userno=:userno";
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("passwd", passwd);
		params.put("userno", userno);
		dao.executeSql(sql, params);
	}
	public Map<String, Object> getBugroupInfo(Long rowid){
		String sql = "select * from bugroup where rowid = :rowid";
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("rowid", rowid);
		List<Map<String, Object>> list = (List<Map<String, Object>>) dao.getSqlMapList(sql, params);
		if (null != list && list.size() > 0){
			return list.get(0);
		}
		return null;
	}
	public Map<String, Object> getEmpgroupInfo(Integer userno, String groupcd){
		String sql = "select * from empgroup where userno = :userno and groupcd = :groupcd";
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("userno", userno);
		params.put("groupcd", groupcd);
		List<Map<String, Object>> list = (List<Map<String, Object>>) dao.getSqlMapList(sql, params);
		if (null != list && list.size() > 0){
			return list.get(0);
		}
		return null;
	}
	public Map<String, Object> getDeptInfo(Long rowid){
		String sql = "select * from dept where rowid = :rowid";
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("rowid", rowid);
		List<Map<String, Object>> list = (List<Map<String, Object>>) dao.getSqlMapList(sql, params);
		if (null != list && list.size() > 0){
			return list.get(0);
		}
		return null;
	}
	public Map<String, Object> getMeasempInfo(Long rowid, String measure_id){
		String sql = "select * from measemp where rowid = :rowid and measure_id =:measure_id";
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("rowid", rowid);
		params.put("measure_id", measure_id);
		List<Map<String, Object>> list = (List<Map<String, Object>>) dao.getSqlMapList(sql, params);
		if (null != list && list.size() > 0){
			return list.get(0);
		}
		return null;
	}
	public Map<String, Object> getFoodempInfo(Long rowid){
		String sql = "select * from foodemp where rowid = :rowid";
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("rowid", rowid);
		List<Map<String, Object>> list = (List<Map<String, Object>>) dao.getSqlMapList(sql, params);
		if (null != list && list.size() > 0){
			return list.get(0);
		}
		return null;
	}
	public Map<String, Object> getExerempInfo(Long rowid){
		String sql = "select * from exeremp where rowid = :rowid";
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("rowid", rowid);
		List<Map<String, Object>> list = (List<Map<String, Object>>) dao.getSqlMapList(sql, params);
		if (null != list && list.size() > 0){
			return list.get(0);
		}
		return null;
	}
	public Map<String, Object> getHactivityInfo(Long rowid){
		String sql = "select * from hactivity where rowid = :rowid";
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("rowid", rowid);
		List<Map<String, Object>> list = (List<Map<String, Object>>) dao.getSqlMapList(sql, params);
		if (null != list && list.size() > 0){
			return list.get(0);
		}
		return null;
	}
	public Map<String, Object> getHPProEventInfo(Integer event_uid){
		String sql = "select * from HP_pro_event where event_uid = :event_uid";
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("event_uid", event_uid);
		List<Map<String, Object>> list = (List<Map<String, Object>>) dao.getSqlMapList(sql, params);
		if (null != list && list.size() > 0){
			return list.get(0);
		}
		return null;
	}
	
	public Map<String, Object> getHPMedicineSugInfo(Long rowid){
		String sql = "select * from HP_medicine_sug where rowid = :rowid";
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("rowid", rowid);
		List<Map<String, Object>> list = (List<Map<String, Object>>) dao.getSqlMapList(sql, params);
		if (null != list && list.size() > 0){
			return list.get(0);
		}
		return null;
	}
	public Map<String, Object> getCalendarlogInfo(Integer rowid){
		String sql = "select * from hp_reminder where rowid = :rowid";
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("rowid", rowid);
		List<Map<String, Object>> list = (List<Map<String, Object>>) dao.getSqlMapList(sql, params);
		if (null != list && list.size() > 0){
			return list.get(0);
		}
		return null;
	}
	public Map<String, Object> getHPMeasureItemsInfo(String measure_id){
		String sql = "select * from HP_measure_items where measure_id = :measure_id";
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("measure_id", measure_id);
		List<Map<String, Object>> list = (List<Map<String, Object>>) dao.getSqlMapList(sql, params);
		if (null != list && list.size() > 0){
			return list.get(0);
		}
		return null;
	}
	public Map<String, Object> getHPKnowledgeInfo(Integer rowid, Long pro_userno){
		String sql = "select * from HP_Knowledge where rowid = :rowid ";
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("rowid", rowid);
		if (pro_userno != null){
			sql += " and pro_userno = :pro_userno ";
			params.put("pro_userno", pro_userno);
		}
		List<Map<String, Object>> list = (List<Map<String, Object>>) dao.getSqlMapList(sql, params);
		if (null != list && list.size() > 0){
			return list.get(0);
		}
		return null;
	}
	public Map<String, Object> getFoodcalorInfo(Long rowid){
		String sql = "select * from foodcalor where rowid = :rowid";
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("rowid", rowid);
		List<Map<String, Object>> list = (List<Map<String, Object>>) dao.getSqlMapList(sql, params);
		if (null != list && list.size() > 0){
			return list.get(0);
		}
		return null;
	}
	public List<Map<String, Object>> getHactivityList(String lastTime, String nowTime){
		String sql = "select * from Hactivity where actbdate>:lastTime and actbdate<=:nowTime";
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("lastTime", lastTime);
		params.put("nowTime", nowTime);
		return (List<Map<String, Object>>) dao.getSqlMapList(sql, params);
	}
	public List<Map<String, Object>> getHPMedicineSugList(){
		String sql = "select * from HP_medicine_sug ";
		return (List<Map<String, Object>>) dao.getSqlMapList(sql, null);
	}
	public List<Map<String, Object>> getCalendarlogList(){
		String sql = "select * from hp_reminder ";
		return (List<Map<String, Object>>) dao.getSqlMapList(sql, null);
	}
	public void saveLoginUser(String userId, String channelId){
		String sql = "insert into login_user (user_id,channel_id) VALUES (:userId,:channelId)";
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("userId", userId);
		params.put("channelId", channelId);
		mydao.executeSql(sql, params);
	}
	/**
	 */
	public List<Map<String, Object>> getPushHPMedicineSugList(String lastTime, String nowTime){
		StringBuffer sql = new StringBuffer();
		sql.append("select * from HP_medicine_sug where createdate > :lastTime and createdate <= :nowTime");
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("lastTime", lastTime);
		params.put("nowTime", nowTime);
		List<Map<String, Object>> list1 = (List<Map<String, Object>>) dao.getSqlMapList(sql.toString(), params);
		return list1;
	}
	
	public List<Map<String, Object>> getLoginUserList(){
		String sql = "select * from login_user";
		return (List<Map<String, Object>>) mydao.getSqlMapList(sql, null);
	}
	
	
	public List<Map<String, Object>> getPushCalendarlogList(String lastTime, String nowTime){
		StringBuffer sql = new StringBuffer();
		sql.append("SELECT * FROM hp_reminder")
		.append(" WHERE CreateDate >:lastTime")
		.append(" AND CreateDate <= :nowTime");
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("lastTime", lastTime);
		params.put("nowTime", nowTime);
		List<Map<String, Object>> list1 = (List<Map<String, Object>>) dao.getSqlMapList(sql.toString(), params);
		return list1;
	}
	public List<Map<String, Object>> getMeasempList(String lastTime, String nowTime){
		StringBuffer sql = new StringBuffer();
		sql.append("SELECT a.*,b.measure_name FROM measemp a left join dbo.HP_measure_items b on a.measure_id = b.measure_id ")
		.append(" WHERE convert(datetime,CONVERT(varchar(100), a.datadate, 23) + ' ' +a.keeptime) >:lastTime")
		.append(" AND convert(datetime,CONVERT(varchar(100), a.datadate, 23) + ' ' +a.keeptime) <= :nowTime");
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("lastTime", lastTime);
		params.put("nowTime", nowTime);
		List<Map<String, Object>> list1 = (List<Map<String, Object>>) dao.getSqlMapList(sql.toString(), params);
		return list1;
	}
	public List<Map<String, Object>> getExerempList(String lastTime, String nowTime){
		StringBuffer sql = new StringBuffer();
		sql.append("SELECT a.*,b.descr as exername FROM exeremp a left join exercise b on a.exercd = b.exercd ")
		.append(" WHERE convert(datetime,CONVERT(varchar(100), a.datadate, 23) + ' ' +a.exertime) >:lastTime")
		.append(" AND convert(datetime,CONVERT(varchar(100), a.datadate, 23) + ' ' +a.exertime) <= :nowTime");
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("lastTime", lastTime);
		params.put("nowTime", nowTime);
		List<Map<String, Object>> list1 = (List<Map<String, Object>>) dao.getSqlMapList(sql.toString(), params);
		return list1;
	}
	public List<Map<String, Object>> getFoodempList(String lastTime, String nowTime){
		StringBuffer sql = new StringBuffer();
		sql.append("SELECT * FROM foodemp")
		.append(" WHERE datadate >:lastTime")
		.append(" AND datadate <= :nowTime");
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("lastTime", lastTime);
		params.put("nowTime", nowTime);
		List<Map<String, Object>> list1 = (List<Map<String, Object>>) dao.getSqlMapList(sql.toString(), params);
		return list1;
	}
	public List<Map<String, Object>> getHPProEventList(String lastTime, String nowTime){
		StringBuffer sql = new StringBuffer();
		sql.append("SELECT * FROM HP_pro_event")
		.append(" WHERE event_date >:lastTime")
		.append(" AND event_date <= :nowTime");
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("lastTime", lastTime);
		params.put("nowTime", nowTime);
		List<Map<String, Object>> list1 = (List<Map<String, Object>>) dao.getSqlMapList(sql.toString(), params);
		return list1;
	}
	public void deleteLoginUser(String userId){
		String sql = "delete from login_user where user_id = :userId";
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("userId", userId);
		mydao.executeSql(sql, params);
	}

	@Override
	public List<Map<String, Object>> getMeasempList(Map<String, String> query) {
		StringBuffer sql = new StringBuffer();
		sql.append("select a.*,b.measure_name from measemp a " +
				"left join HP_measure_items b on a.measure_id=b.measure_id where 1=1");
		Map<String, Object> params = new HashMap<String, Object>();
		if (StringUtils.isNotBlank(query.get("measure_id"))){
			sql.append(" and a.measure_id = :measure_id");
			params.put("measure_id", query.get("digest"));
		}
		if (StringUtils.isNotBlank(query.get("userno"))){
			sql.append(" and a.userno = :userno");
			params.put("userno", query.get("descr"));
		}
		if (StringUtils.isNotBlank(query.get("strTime"))){
			sql.append(" and a.datadate >= :strTime");
			params.put("strTime", query.get("strTime"));
		}
		if (StringUtils.isNotBlank(query.get("endTime"))){
			sql.append(" and a.datadate <= :endTime");
			params.put("endTime", query.get("endTime"));
		}
		sql.append(" order by datadate,keeptime asc");
		return (List<Map<String, Object>>) dao.getSqlMapList(sql.toString(), query);
	}

	@Override
	public List<Map<String, Object>> getExerempList(Map<String, String> query) {
		StringBuffer sql = new StringBuffer();
		sql.append("select a.*,b.descr as exername from exeremp a " +
				"left join exercise b on a.exercd = b.exercd where a.userno=:userno");
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("userno", query.get("userno"));
		if (StringUtils.isNotBlank(query.get("descr"))){
			sql.append(" and a.descr like :descr");
			params.put("descr", "%" + query.get("descr") + "%");
		}
		if (StringUtils.isNotBlank(query.get("strTime"))){
			sql.append(" and a.datadate >= :strTime");
			params.put("strTime", query.get("strTime"));
		}
		if (StringUtils.isNotBlank(query.get("endTime"))){
			sql.append(" and a.datadate <= :endTime");
			params.put("endTime", query.get("endTime"));
		}
		return (List<Map<String, Object>>) dao.getSqlMapList(sql.toString(), query);
	}
	
	@Override
	public List<Map<String, Object>> getFoodempList(Map<String, String> query) {
		StringBuffer sql = new StringBuffer();
		sql.append("select a.*,b.descr as periodname,c.frequency_name from dbo.HP_goal_food a "
				+ "left join foodperiod b on a.periodcd=b.periodcd "
				+ "left join dbo.HP_goal_frequency c on a.frequency_id=c.frequency_id where a.userno=:userno");
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("userno", query.get("userno"));
		if (StringUtils.isNotBlank(query.get("userno"))){
			sql.append(" and a.userno = :userno");
			params.put("userno", query.get("descr"));
		}
		if (StringUtils.isNotBlank(query.get("strTime"))){
			sql.append(" and a.end_date >= :strTime");
			params.put("strTime", query.get("strTime"));
		}
		if (StringUtils.isNotBlank(query.get("endTime"))){
			sql.append(" and a.start_date <= :endTime");
			params.put("endTime", query.get("endTime"));
		}
		sql.append(" order by created_date desc");
		return (List<Map<String, Object>>) dao.getSqlMapList(sql.toString(), query);
	}
	
	@Override
	public List<Map<String, Object>> getHPMeasureItemsList(
			Map<String, String> query) {
		String sql = "select * from HP_measure_items";
		Map<String, Object> params = new HashMap<String, Object>();
		return (List<Map<String, Object>>) dao.getSqlMapList(sql, params);
	}
	public String getLastWorkTime(){
		String sql = "select * from work_info where id =1";
		List<Map<String, Object>> list = (List<Map<String, Object>>) mydao.getSqlMapList(sql, null);
		if (null != list && list.size() > 0){
			Map<String, Object> map = list.get(0);
			String time = ParseDate.parseFullFormat(ParseDate.fromFullFormat(map.get("work_time").toString()));
			return time;
		}
		return null;
	}
	public void updateWorkTime(String nowTime){
		String sql = "update work_info set work_time = :workTime where id=1";
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("workTime", nowTime);
		mydao.executeSql(sql, params);
	}
}

